//
//  EdudescCell.m
//  iBaby365v2
//
//  Created by admin on 14/12/5.
//  Copyright (c) 2014年 suplus. All rights reserved.
//

#import "EdudescCell.h"
#import "SPEducation.h"
#import "SPEdudescFrame.h"
#import "UIImageView+AFNetworking.h"

@interface EdudescCell ()
/**
 *  标题
 */
@property(nonatomic,weak) UILabel *titleView;
/**
 *  时间
 */
@property(nonatomic,weak) UILabel *timeTextView;
/**
 *  图片
 */
@property(nonatomic,weak)UIImageView *pictureView;
/**
 *  内容
 */
@property(nonatomic,weak) UILabel *contentTextView;

@end

@implementation EdudescCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UILabel *titleView = [[UILabel alloc] init];
        titleView.font = [UIFont systemFontOfSize:17];
//        titleView.numberOfLines = 0;
        [self.contentView addSubview:titleView];
        self.titleView = titleView;
        
        UILabel *timeTextView = [[UILabel alloc] init];
//        timeTextView.numberOfLines = 0;
        timeTextView.font = [UIFont systemFontOfSize:14];
        timeTextView.textColor = [UIColor lightGrayColor];
        [self.contentView addSubview:timeTextView];
        self.timeTextView = timeTextView;
        
        UIImageView *pictureView = [[UIImageView alloc] init];
        [self.contentView addSubview:pictureView];
        self.pictureView = pictureView;
        
        // 4.正文
        UILabel *textView = [[UILabel alloc] init];
        textView.numberOfLines = 0;
        textView.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:textView];
        self.contentTextView = textView;
        
    }
    return self;
}

-(void)setEducationFrame:(SPEdudescFrame *)educationFrame
{
    _educationFrame = educationFrame;
    SPEducation *speducation = self.educationFrame.education;
    self.titleView.text = speducation.title;
    self.timeTextView.text = speducation.createTime;
    [self.pictureView setImageWithURL:[NSURL URLWithString:speducation.photo] placeholderImage:nil];
    self.contentTextView.text = speducation.content;
    
    self.titleView.frame = self.educationFrame.titleF;
    self.timeTextView.frame = self.educationFrame.timeF;
    self.pictureView.frame = self.educationFrame.pictureF;
    self.contentTextView.frame = self.educationFrame.contentF;
}

/**
 *  计算文字尺寸
 *
 *  @param text    需要计算尺寸的文字
 *  @param font    文字的字体
 *  @param maxSize 文字的最大尺寸
 */
- (CGSize)sizeWithText:(NSString *)text font:(UIFont *)font maxSize:(CGSize)maxSize
{
    NSDictionary *attrs = @{NSFontAttributeName : font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attrs context:nil].size;
}

+(instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString *ID = @"spedudesc";
    EdudescCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[EdudescCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
}

@end
